package com.syn.michat.im;

import javax.websocket.Session;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class WebSocketSessionManager {

    public static ConcurrentHashMap<String, Session> sessionMap = new ConcurrentHashMap<>();

    public static void add(String userId, Session session) {
        if (sessionMap.containsKey(userId)) {
            sessionMap.remove(userId);
        }
        sessionMap.put(userId, session);

//        WebSocketSessionManager.sessionMap.put(userId, session);
    }

    public static void remove(Session session) {
        for(Map.Entry<String, Session> entry : sessionMap.entrySet()){
            if (entry.getValue() == session) {
                sessionMap.remove(entry.getKey());
            }
        }
    }
}
